﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BizTalk.ESB.Extensions.Helpers
{
    [Serializable]
    public class BusinessDataTrackingInstructions
    {
        private const string TracePrefix = "[BusinessDataMonitor] ";

        public string ProcessName { get; set; }
        public string StepName { get; set; }

        public bool DebugFlag { get; set; }
        public bool IsFaultPublished { get; set; }
        public bool StopOnError { get; set; }

        public string BamActivityDefinitionName { get; set; }
        public BamEventTypes BamEventType { get; set; }
        public string TrackingConfig { get; set; }
        public int FlushThreshold { get; set; }
        public int TimeoutSeconds { get; set; }

        public string BAMConnectionString { get; set; }
        public string MsgBoxConnectionString { get; set; }

        public bool HasError { get; set; }
        public bool TrackingSucceeded { get; set; }
        public bool HasNextStep { get; set; }

        public BusinessDataTrackingInstructions()
        {
            TrackingSucceeded = false;
            StopOnError = true;
            HasError = false;
            FlushThreshold = 0;
            TimeoutSeconds = 60;
            IsFaultPublished = false;
        }

        public void TraceItineraryService(string BizTalkServiceName, string BizTalkServiceID)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ProcessName: " + this.ProcessName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "StepName: " + this.StepName, System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Debug Flag: " + this.DebugFlag.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Fault Published: " + this.IsFaultPublished.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "StopOnError: " + this.StopOnError.ToString(), System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Activity Definition Name: " + this.BamActivityDefinitionName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Event Stream Type: " + this.BamEventType.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Tracking Configuration: " + this.TrackingConfig, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Flush Threshold: " + this.FlushThreshold.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Timeout: " + this.TimeoutSeconds.ToString(), System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "BAM Connection String: " + this.BAMConnectionString, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "MessageBox Connection String: " + this.MsgBoxConnectionString, System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "HasError: " + this.HasError.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Tracking Succeeded: " + this.TrackingSucceeded.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "HasNextStep: " + this.HasNextStep.ToString(), System.Diagnostics.EventLogEntryType.Information));
        }
    }
}
